package com.itheima.controller;

import com.itheima.pojo.Result;
import com.itheima.pojo.Student;
import com.itheima.pojo.StudentQueryParam;
import com.itheima.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class StudentController {
@Autowired
    StudentService ss;
//分页查询学生信息
    @GetMapping("/students")
    public Result getStudents(StudentQueryParam sqp){
        return Result.success(ss.getStudents(sqp));
    }
    //新增学生信息
    @PostMapping("/students")
    public Result addStudents(@RequestBody Student student){
        ss.addStudents(student);
        return Result.success();
    }
    //根据id查询学员
    @GetMapping("/students/{id}")
    public Result getStuById(@PathVariable Integer id){
        return Result.success(ss.getStuById(id));
    }
    //修改学员
    @PutMapping("/students")
    public Result updateStu(@RequestBody Student s){
        ss.updateStu(s);
        return Result.success();
    }
    @DeleteMapping("/students/{ids}")
    public Result deleteStu(@PathVariable String ids){
        String[] idArray = ids.split(",");
        List<Integer> idss=new ArrayList<>();
        for(String a:idArray) {
            idss.add(Integer.valueOf(a));
        }
        ss.deleteStu(idss);
     return Result.success();
    }
    @PutMapping("/students/violation/{id}/{score}")
    public Result viji(@PathVariable("id")Integer id,@PathVariable("score")Integer score){
        ss.viji(id,score);
        return Result.success();
    }
   /* @GetMapping("/report/studentDegreeData")
    public Result*/
}
